package com.xrit.sunnyday.controller;

import com.xrit.sunnyday.common.Result;
import com.xrit.sunnyday.common.SunnydayException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.security.access.AccessDeniedException;
//全局异常处理类
@RestControllerAdvice//在所有有controller的注解上进行增强
public class MyControllerException {
    //处理异常类(预知异常)
    @ExceptionHandler(SunnydayException.class)
    public Result HandlerException(SunnydayException se){
        return new Result(false,se.getMessage());
    }
    @ExceptionHandler(AccessDeniedException.class)
    public Result AccessDeniedException(AccessDeniedException accessDeniedException){
        return new Result(false,accessDeniedException.getMessage()+"权限不足");
    }
}